package com.peng.leetcode.array;

/**
 * CombinationSum4
 * <p>
 * 377. 组合总和 Ⅳ
 *
 * @author: lupeng6
 * @create: 2021/4/24 20:50
 */
public class CombinationSum4 {


    public static void main(String[] args) {

    }

    private int answer = 0;

    private int target;

    public int combinationSum4(int[] nums, int target) {
        if (nums.length == 0) {
            return 0;
        }
        this.target = target;
        dfs(nums, 0, 0);
        return answer;
    }

    private void dfs(int[] nums, int index, int sum) {
        if (nums.length == index) {
            return;
        }
        if (sum == target) {
            this.answer++;
            return;
        }
        dfs(nums, index + 1, sum + nums[index]);
        dfs(nums, index + 1, sum);
    }
}
